using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using System.Collections;

namespace ElevatorSpeeches.Framework
{
        
    [ActiveRecord]
    [Serializable]
    public class SpeechTopic : SpeechTopicBase<SpeechTopic>
    {

        private IList _Speeches = new List<Speech>();
        [HasMany(typeof(Speech))]
        public IList Speeches
        {
            get
            {
                return _Speeches;
            }
            set
            {
                if (_Speeches == value)
                    return;
                _Speeches = value;
            }
        }

        private IList _Nouns = new List<Noun>();
		[HasAndBelongsToMany(typeof(Noun), Table = "SpeechTopicTerms", ColumnRef = "NounID", ColumnKey = "SpeechTopicID")]
        public IList Nouns
        {
            get
            {
				return _Nouns;
            }
            internal set
            {
				_Nouns = value;
            }
        }

        public static SpeechTopic FindByPrettyUrl(string prettyUrl)
        {
            return SpeechTopic.FindOne(new NHibernate.Expression.EqExpression("PrettyUrl", prettyUrl));
        }

        public static SpeechTopic Create(string Title)
        {           
//            if (SpeechTopic.Exists(new NHibernate.Expression.EqExpression("Title", Title)))
//                throw new ArgumentException("Can not create a speech topic that already exists");

            SpeechTopic rv = new SpeechTopic();
            rv.Title = Title;
            return rv;            
        }
    }
}
